﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	
	<script type="text/javascript">
		var storage_goodsName_formatter = function(value,row,index) 
		{
			if(row.goodsBean) 
			{
				return row.goodsBean.name;
			}
			return row.goodsName;
		}
		var storage_goodsId_formatter = function(value,row,index) 
		{
			if(row.goodsBean) 
			{
				return row.goodsBean.id;
			}
		}
		function cellStyler_goodsName(value,row,index)
		{
			if(row.goods) 
			{
				return "color:blue";
			}
		}
		var cellFormatter_goodsStock = function(value,row,index) 
		{
			if(row.goods) 
			{
				return value;
			}
		}
		var orderStatusFormatter2 = function (value, row, index) 
		{
			if(value == '0') 
			{
				return '<font color="blue">新建</font>';
			}
			else if(value == '1') 
			{
				return '<font color="red">退回</font>';
			}
			else if(value == '2') 
			{
				return '<font color="orange">取消</font>';
			}
			else if(value == '3') 
			{
				return '<font color="green">完成</font>';
			}
		}
		var orderTooltipFormatter = function (value, row, index) 
		{
			return "<a href='javascript:void(0)' id='"+value+"'>" + value + "</a>";
		}
		var showOrderDetail = function (orderId) 
		{
			//console.log(orderId);
			$('#dlg-view-storage-course a#' + orderId).tooltip({
                content: $('<div></div>'),
                showEvent: 'click',
                onUpdate: function(content){
                    content.panel({
                        width: 300,
                        border: false,
                        title: '订单明细',
						method: 'post',
						queryParams:{orderId:orderId},
                        href: '<c:url value='/outOrder/getOrderDetailByOrderId.html' />'
                    });
                },
                onShow: function(){
                    var t = $(this);
                    t.tooltip('tip').unbind().bind('mouseenter', function(){
                        t.tooltip('show');
                    }).bind('mouseleave', function(){
                        t.tooltip('hide');
                    });
                }
            });
		}
		
		var viewStorageCallback = function () 
		{
			var row = $('#dg-storage').datagrid('getSelected');
			if(row) 
			{
				$('#dlg-storage #fm-storage #goodsName').val (row.goodsBean.name);
			}
		}
		
		var onGoodsStorageRowContextMenu = function(e, row) 
		{
			e.preventDefault();
			$(this).treegrid('select',row.id);
			if(row.goods) 
			{
				$('#mm_goodsStorage').menu('show',{
					left: e.pageX,
					top: e.pageY
				});
			}
		}
		
		var pageInfo = {page: 1, rows: 10};
		var onBeforeLoadStorageCourse = function (param) 
		{
			pageInfo = param;
			//var startDate = $('#toolbar-customer-payment #advanceSearchSpan #startDate').combo('getValue');
			//var endDate = $('#toolbar-customer-payment #advanceSearchSpan #endDate').combo('getValue');
			//var customerId = $('#toolbar-customer-payment #advanceSearchSpan #customerId').combo('getValue');
			/*if(startDate == '' && endDate == '' && customerId == '') 
			{
				var timeFrame = $('#toolbar-customer-payment #advanceSearchSpan #timeFrame').combo('getValue');
				startDate = generateStartDate(timeFrame);
				endDate = new Date().format("yyyy-MM-dd");
				$('#toolbar-customer-payment #advanceSearchSpan #startDate').datebox('setValue', startDate);
				$('#toolbar-customer-payment #advanceSearchSpan #endDate').datebox('setValue', endDate);
				
				startDate = $('#toolbar-customer-payment #advanceSearchSpan #startDate').combo('getValue');
				endDate = $('#toolbar-customer-payment #advanceSearchSpan #endDate').combo('getValue');
			}*/
			
			var goodsStorage = $('#dg-storage').datagrid('getSelected');
			$('#dg-storage-course').datagrid('options').url = "<c:url value='/goodsStorage/getStorageCourse.html' />?goodsId="+goodsStorage.goodsBean.id;
			return true;
		}
		var viewStorageCourse = function() 
		{
			var goodsStorage = $('#dg-storage').datagrid('getSelected');
			if (goodsStorage) {
				$('#dlg-view-storage-course').dialog('open').dialog('setTitle', '货物' + goodsStorage.goodsBean.name + '的经营历程');
				
				/*var pageOptions = $('#dg-storage-course').datagrid('getPager').data("pagination").options;
				var page = pageOptions.pageNumber;
				var rows = pageOptions.pageSize;
				loadGridData ('#dg-storage-course', '<c:url value='/goodsStorage/getStorageCourse.html' />', {page:page, rows:rows, goodsId : goodsStorage.goodsBean.id});*/
				$('#dg-storage-course').datagrid('options').onBeforeLoad = onBeforeLoadStorageCourse;
				$('#dg-storage-course').datagrid('reload');
			}
		}
		var onLoadStorageCourseSuccess = function(data) 
		{
			for(var i = 0; i < data.rows.length; i ++) 
			{
				showOrderDetail(data.rows[i].orderId);
			}
		}
	</script>
	
	<div style="width:100%; height:450px;">
		<table id="dg-storage" title="<spring:message code="goodsStorage.management" />" class="easyui-treegrid" url="<c:url value='/goodsStorage/asyncGetStorages2.html' />" 
			rownumbers="true" singleSelect="true" checkOnSelect="true" selectOnCheck="false" showFooter="true"  
			data-options="fitColumns:true, idField:'id',treeField:'goodsName', fit:true, onContextMenu:onGoodsStorageRowContextMenu">
			<thead>
				<tr>
					<!-- <th data-options="field:'ck',checkbox:true"></th> -->
					<th data-options="field:'id',hidden:true"></th>
					<th field="goodsId" data-options="hidden:true, formatter:storage_goodsId_formatter"></th>
					<th field="goodsName" width="200" data-options="styler:cellStyler_goodsName, formatter:storage_goodsName_formatter"><spring:message code="goodsStorage.goods" /></th>
					<th field="initialStock" width="50" data-options="formatter:cellFormatter_goodsStock"><spring:message code="goodsStorage.initialStock" /></th>
					<th field="currentStock" width="50" data-options="formatter:cellFormatter_goodsStock"><spring:message code="goodsStorage.currentStock" /></th>
					<th field="minStock" width="50" data-options="formatter:cellFormatter_goodsStock"><spring:message code="goodsStorage.minStock" /></th>
					<th field="maxStock" width="50" data-options="formatter:cellFormatter_goodsStock"><spring:message code="goodsStorage.maxStock" /></th>
					<th field="createTime" width="80"><spring:message code="goodsStorage.createDate" /></th>
					<th field="updateTime" width="80"><spring:message code="goodsStorage.updateDate" /></th>
					<th field="userCreated" width="50">创建人</th>
					<th field="userUpdated" width="50"><spring:message code="goodsStorage.updateUser" /></th>
					<th field="comment" width="50"><spring:message code="goodsStorage.comment" /></th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="toolbar-storage">
		<%-- <a href="javascript:void(0)" class="easyui-linkbutton" 
			iconCls="icon-add" plain="true" onclick="newModel('#dlg-storage', '新增货品库存', '#fm-storage', '<c:url value='/goodsStorage/newStorage.html' />')" title="新增货品库存"></a> --%> 
		<%-- <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" 
			onclick="editModel('#dg-storage', '#dlg-storage', '<spring:message code="goodsStorage.editStock" />', '#fm-storage', '<c:url value='/goodsStorage/updateStorage.html' />', viewStorageCallback)" title="<spring:message code="goodsStorage.editStock" />"></a> --%> 
	</div>
	
	<!-- 右键菜单 -->
	<div id="mm_goodsStorage" class="easyui-menu" style="width:120px;">
        <div data-options="iconCls:'icon-search'" onclick="viewStorageCourse()">查看经营历程</div>
    </div>
	<!-- 右键菜单 -->

	<div id="dlg-storage" class="easyui-dialog"
		style="width: 400px; height: 300px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-storage" data-options="modal:true">
		<div class="ftitle"></div>
		<form id="fm-storage" class="fm" method="post" novalidate>
			<div class="fitem divHidden">
				<input id="goodsId" name="id">
			</div>
			<div class="fitem">
				<label style="width:60px;"><spring:message code="goodsStorage.goods" />:</label> 
				<input id="goodsName" name="goodsName" readonly="readonly" style="width:210px; border:none;">
			</div>
			<div class="fitem">
				<label><spring:message code="goodsStorage.currentStock" />:</label> 
				<input id="currentStock" name="currentStock" class="easyui-validatebox" required="true" />
			</div>
		</form>
	</div>
	<div id="dlg-buttons-storage">
		<a id="save-storage" href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-storage', '#dlg-storage', '#fm-storage')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-storage').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	
	<!-- 查看库存历程 -->
	<div id="dlg-view-storage-course" class="easyui-dialog"
		style="width: 750px; height: 420px; padding: 5px;" closed="true"
		buttons="#dlg-buttons-view-storage-course" data-options="modal:true">
		<div id="" style="margin-top: 5px;">
			<table id="dg-storage-course" class="easyui-datagrid"
				style="width: 700px; height: 320px" url="" rownumbers="true"
				singleSelect="true" fitColumns="true" data-options="pagination:true, onLoadSuccess:onLoadStorageCourseSuccess">
				<thead>
					<tr>
						<th data-options="field:'goodsId',hidden:true"></th>
						<th field="goodsName" width="100" data-options="styler:cellStyler_goodsNameBlue">货物</th>
						<th field="orderId" width="100" data-options="formatter:orderTooltipFormatter">订单号</th>
						<th field="orderCreateDate" width="100">下单时间</th>
						<th field="customerId" hidden="true" width="50"></th>
						<th field="customerName" width="80">客户或供应商</th>
						<th field="orderTypeCode" width="50" data-options="formatter:orderTypeFormatter">订单类型</th>
						<th field="orderStatusCode" width="50" data-options="formatter:orderStatusFormatter2">订单状态</th>
						<th field="amount" width="50">数量</th>
						<th field="goodsPrice" width="50">单价</th>
						<!-- <th field="currentStock" width="50">当前库存</th> -->
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<div id="dlg-buttons-view-storage-course">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#dlg-view-storage-course').dialog('close')">关闭</a>
	</div>
	<!-- 查看库存历程 -->
